<!--
 * @Author: your name
 * @Date: 2020-06-01 14:45:03
 * @LastEditTime: 2020-07-03 17:24:59
 * @LastEditors: Please set LastEditors
 * @Description: 聊天列表
 * @FilePath: \IM_Web\im_web\src\components\imList\imlist.vue
--> 
<template>
    <div class="list">
        <div v-if="sessionsData.length === 0" class="no_session">暂无会话记录</div>
        <div v-else>
            <div
                v-for="item in sessionsData"
                :key="item.topic"
                class="flex justify_between list_content"
                :class="item.topic === $store.state.currSessionId ?'active':''"
                @click="inSession(item)"
            >
                <Badge :count="item.unread" :overflow-count="99" :offset="[5,20]">
                    <div class="avatar">
                        <Avatar
                            :src=" item.public.avatar"
                            shape="square"
                            style="width:100%;height:100%;"
                        />
                    </div>
                </Badge>
                <div class="list_right flex flex_direction justify_between">
                    <div class="flex justify_between">
                        <div class="basis_lg user_name">{{item.public.fn}}</div>
                        <div
                            class="basis_sm"
                            style="color:#999999;font-size:18px;text-align:right;"
                        >{{item.updateTimeShow}}</div>
                    </div>
                    <div class="chat_synopsis">{{item.lastMsgShow}}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
// import store from "../../store";
export default {
    props: {
        sessionsData: {
            type: Array,
            default() {
                return [];
            }
        }
    },
    data() {
        return {
            day: new Date().getDate()
        };
    },
    computed: {},
    created() {
        // console.log(this.sessionsData);
    },
    mounted() {},
    watch: {},
    methods: {
        teaEncode() {},
        inSession(params) {
            console.log(params);
            // this.$store.dispatch("updateCurrSessionId",params.lastMsg)
            if (this.$store.state.currSessionId === params.topic) {
                return false;
            }
            this.$store.dispatch("resetCurrSession");
            let obj = {
                scene: params.scene,
                to: params.to,
                type: "init",
                sessionId: params.topic
            };
            console.log(params);
            
            this.$store.dispatch("resetNoMoreHistoryMsgs");
            this.getHistoryMsgs(obj);
            this.$emit("goInSession", {
                account: params.public.fn,
                name: params.public.fn,
                sessionId: params.topic,
                scene: params.scene
            });
        },
        getHistoryMsgs(obj) {
            console.log("getHistoryMsgs", obj);
            this.$store.dispatch("resetBeforeId");
            // if (this.canLoadMore) {
            this.$store.dispatch("getHistoryMsgs", {
                scene: obj.scene,
                to: obj.to,
                sessionId: obj.sessionId
            });
            // }
        }
    },
    components: {}
};
</script>

<style scoped lang="less">
.list {
    height: 650px;
    max-height: 650px;
    overflow-y: auto;
    background: #fff;
    .no_session {
        font-size: 16px;
        color: #999999;
        padding: 20px 0;
    }
    .active {
        background: #dedede;
    }
    .list_content:hover {
        background: #dedede;
    }
    .list_content {
        height: 90px;
        padding: 10px 20px 10px 12px;
        border-bottom: 1px solid #cccccc;
        box-sizing: border-box;
        cursor: pointer;
        .avatar {
            width: 70px;
            height: 70px;
            // background: #ddd;
            margin-right: 12px;
            display: inline-block;
            background-size: 100% 100%;
            // margin-right: px;
        }
        .list_right {
            width: 80%;
            font-size: 18px;
            .chat_synopsis {
                width: 211px;
                // padding: 2px 0;
                margin-top: 8px;
                // box-sizing: border-box;
                white-space: nowrap;
                text-overflow: ellipsis;
                overflow: hidden;
                color: #999999;
                text-align: left;
            }
            .user_name {
                max-width: 150px;
                white-space: nowrap;
                text-overflow: ellipsis;
                overflow: hidden;
                text-align: left;
            }
        }
    }
}
.list::-webkit-scrollbar {
    /*滚动条整体样式*/
    width: 5px;
    /*高宽分别对应横竖滚动条的尺寸*/
    height: 5px;
}

.list::-webkit-scrollbar-thumb {
    /*滚动条里面小方块*/
    border-radius: 10px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: #409eff;
}

.list::-webkit-scrollbar-track {
    /*滚动条里面轨道*/
    // box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    // border-radius: 10px;
    background: rgba(0, 0, 0, 0);
}
</style>
